package com.fillifesoft.magicHitter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.fillifesoft.magicHitter.controller.Generator;
import com.fillifesoft.magicHitter.manager.ResourceManager;

public class MagicHitter implements Runnable {
	
	public static final int REPO_LEN = 45;
	public static final int REPEAT_COUNT = 2000;
	public static final int MAX_NUMBER_COUNT = 6;
	
	public static final String MYBATIS_CONF_FILE = "mybatis-config.xml";
	
	ResourceManager resourceManager = ResourceManager.getInstance();
	
	public void run() {
		System.out.println("Starting MagicHitter..");
		
		int repeatCount = keyInRepeatCount();
		Generator g = new Generator(repeatCount);
		g.generate();

		System.out.println("End..");
		resourceManager.close();
	}
	
	public int keyInRepeatCount() {
		int repeatCount = -1;
		while(true) {
			if(repeatCount > 0)	 {
				break;
			}
			
			try {
				InputStreamReader link=new InputStreamReader(System.in);
				BufferedReader r= new BufferedReader(link);
	   
				System.out.print("Input Repeat count : ");
				repeatCount = Integer.parseInt(r.readLine());
			}
			catch(NumberFormatException e) {
				System.out.println("Wrong Format. Retry...");
			}
			catch (IOException e) {
				e.printStackTrace();
			}
		}
		return repeatCount;
	}
	
	public static void main(String[] args) {
		Thread t = new Thread(new MagicHitter());
		//t.setDaemon(true);
		t.start();
	}
}
